<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>密码：<input type="text" id="password"></div>
    <div>确认密码：<input type="text" id="password-confirm"><span id="message"></span></div>
    <button id="btn-submit">提交</button>
</body>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>

    const $password = $("#password");
    const $passwordConfirm = $("#password-confirm");
    const $message = $("#message");
    const $btnSubmit = $("#btn-submit");

    $password.on("input",function() {
        $passwordConfirm.val(this.value);
    });

    let timeoutId = null;

    $btnSubmit.on("click",function() {
        $message.text("密码错误");
        if (timeoutId) {
            clearTimeout(timeoutId);
        }
        $message.show();
        timeoutId = setTimeout(() => {
            $message.hide();
        },2000);
    })
</script>
</html>